<template>
  <div class='edit-birthday'>
    <van-datetime-picker
      v-model="currentDate"
      type="date"
      title="选择年月日"
      :min-date="minDate"
      :max-date="maxDate"
      @cancel="$emit('closeEditBirthdayShow')"
      @confirm="onConfirm"
    />
  </div>
</template>

<script>
import dayjs from 'dayjs'
import { updateUserProfile } from '@/api/user'
import { Toast } from 'vant'

export default {
  name: 'editBrithday',
  components: {},
  props: {
    value: {
      type: String,
      required: true
    }
  },
  data () {
    return {
      minDate: new Date(1960, 0, 1),
      maxDate: new Date(),
      currentDate: new Date(this.value)
    }
  },
  computed: {},
  watch: {},
  created () {},
  mounted () {},
  methods: {
    async onConfirm (value) {
      Toast.loading({
        message: '请稍后...',
        forbidClick: true
      })
      const date = dayjs(value).format('YYYY-MM-DD')
      await updateUserProfile({
        birthday: date
      })
      this.$emit('closeEditBirthdayShow')
      this.$emit('input', date)
      Toast.success('修改成功')
    }
  }
}
</script>
<style lang='less' scoped></style>
